package cn.liu.poi;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 *
 * @author LIU
 * @version 1.0
 * @description TODO
 * @date 2023/12/27 9:56
 */
public class ExcelWrite {
    public static void main(String[] args) throws Exception {
        /*
         * HSSF 03版使用内存 最大65536行
         *   Invalid row number (65536) outside allowable range (0..65535)
         */
        FileOutputStream fileOutputStream = new FileOutputStream("05_poi/03HSSF.xls");
        Workbook workbook = new HSSFWorkbook();

        // XSSF 07版
//        FileOutputStream fileOutputStream = new FileOutputStream("07XSSF.xlsx");
//        Workbook workbook = new XSSFWorkbook();

        long begin = System.currentTimeMillis();
        Sheet sheet = workbook.createSheet();
        for (int i = 0; i < 65536; i++) {
            Row row = sheet.createRow(i);
            for (int j = 0; j < 8; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(j);
            }
        }

        workbook.write(fileOutputStream);
        fileOutputStream.close();

        System.out.println("执行时间："+ (System.currentTimeMillis() - begin) + "ms");
    }
}
